// 控制全局loading状态
import { defineStore } from 'pinia'
import { LoadingState } from './types';

export const useLoadingStore = defineStore('loading', {
    state: (): LoadingState => ({
      requestCount: 0
    }),
    getters: {
      isLoading: (state) => state.requestCount > 0
    },
    actions: {
      startLoading() {
        this.requestCount += 1
      },
      cancelLoading() {
        if (this.requestCount > 0) {
            this.requestCount -= 1
        }
      }
    }
})